package com.openbravo.data.loader;

import com.openbravo.basic.BasicException;
import java.util.Date;

public class QBFBuilder
  implements ISQLBuilderStatic
{
  private String m_sSentNullFilter;
  private String m_sSentBeginPart;
  private String m_sSentEndPart;
  private String[] m_asFindFields;

  public QBFBuilder(String paramString, String[] paramArrayOfString)
  {
    int i = paramString.indexOf("?(QBF_FILTER)");
    if (i < 0)
    {
      this.m_sSentBeginPart = paramString;
      this.m_sSentEndPart = "";
      this.m_sSentNullFilter = paramString;
    }
    else
    {
      this.m_sSentBeginPart = paramString.substring(0, i);
      this.m_sSentEndPart = paramString.substring(i + 13);
      this.m_sSentNullFilter = (this.m_sSentBeginPart + "(1=1)" + this.m_sSentEndPart);
    }
    this.m_asFindFields = paramArrayOfString;
  }

  public String getSQL(SerializerWrite paramSerializerWrite, Object paramObject)
    throws BasicException
  {
    QBFParameter localQBFParameter = new QBFParameter(this.m_asFindFields);
    if ((paramSerializerWrite == null) || (paramObject == null))
      return this.m_sSentNullFilter;
    paramSerializerWrite.writeValues(localQBFParameter, paramObject);
    String str = localQBFParameter.getFilter();
    if (str.length() == 0)
      return this.m_sSentNullFilter;
    return this.m_sSentBeginPart + "(" + str + ")" + this.m_sSentEndPart;
  }

  private static class QBFParameter
    implements DataWrite
  {
    private String[] m_asFindFields;
    private QBFCompareEnum[] m_aiCondFields;
    private String[] m_aParams;

    public QBFParameter(String[] paramArrayOfString)
    {
      this.m_asFindFields = paramArrayOfString;
      this.m_aiCondFields = new QBFCompareEnum[paramArrayOfString.length];
      this.m_aParams = new String[paramArrayOfString.length];
      for (int i = 0; i < this.m_aParams.length; i++)
        this.m_aParams[i] = DataWriteUtils.getSQLValue((Object)null);
    }

    public void setDouble(int paramInt, Double paramDouble)
      throws BasicException
    {
      if ((paramInt - 1) % 2 == 0)
        throw new BasicException(LocalRes.getIntString("exception.nocompare"));
      this.m_aParams[((paramInt - 1) / 2)] = DataWriteUtils.getSQLValue(paramDouble);
    }

    public void setBoolean(int paramInt, Boolean paramBoolean)
      throws BasicException
    {
      if ((paramInt - 1) % 2 == 0)
        throw new BasicException(LocalRes.getIntString("exception.nocompare"));
      this.m_aParams[((paramInt - 1) / 2)] = DataWriteUtils.getSQLValue(paramBoolean);
    }

    public void setInt(int paramInt, Integer paramInteger)
      throws BasicException
    {
      if ((paramInt - 1) % 2 == 0)
        throw new BasicException(LocalRes.getIntString("exception.nocompare"));
      this.m_aParams[((paramInt - 1) / 2)] = DataWriteUtils.getSQLValue(paramInteger);
    }

    public void setString(int paramInt, String paramString)
      throws BasicException
    {
      if ((paramInt - 1) % 2 == 0)
        throw new BasicException(LocalRes.getIntString("exception.nocompare"));
      this.m_aParams[((paramInt - 1) / 2)] = DataWriteUtils.getSQLValue(paramString);
    }

    public void setTimestamp(int paramInt, Date paramDate)
      throws BasicException
    {
      if ((paramInt - 1) % 2 == 0)
        throw new BasicException(LocalRes.getIntString("exception.nocompare"));
      this.m_aParams[((paramInt - 1) / 2)] = DataWriteUtils.getSQLValue(paramDate);
    }

    public void setBytes(int paramInt, byte[] paramArrayOfByte)
      throws BasicException
    {
      if ((paramInt - 1) % 2 == 0)
        throw new BasicException(LocalRes.getIntString("exception.nocompare"));
      throw new BasicException("Param type not allowed");
    }

    public void setObject(int paramInt, Object paramObject)
      throws BasicException
    {
      if ((paramInt - 1) % 2 == 0)
      {
        if ((paramObject instanceof QBFCompareEnum))
          this.m_aiCondFields[((paramInt - 1) / 2)] = ((QBFCompareEnum)paramObject);
        else
          throw new BasicException(LocalRes.getIntString("exception.nocompare"));
      }
      else
        this.m_aParams[((paramInt - 1) / 2)] = DataWriteUtils.getSQLValue(paramObject);
    }

    public String getFilter()
    {
      StringBuffer localStringBuffer = new StringBuffer();
      for (int i = 0; i < this.m_asFindFields.length; i++)
      {
        String str = this.m_aiCondFields[i].getExpression(this.m_asFindFields[i], this.m_aParams[i]);
        if (str == null)
          continue;
        if (localStringBuffer.length() > 0)
          localStringBuffer.append(" AND ");
        localStringBuffer.append(str);
      }
      return localStringBuffer.toString();
    }
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.data.loader.QBFBuilder
 * JD-Core Version:    0.6.0
 */